<template>
  <div>
    <span style="margin-left: 1rem; font-size: 0.7rem; color: gray"
      >用户名：{{ user }}</span
    >
    <van-cell-group title="选择生产线">
      <van-cell
        v-for="(item, index) in productionLines"
        :key="index"
        :title="item.Line"
        :label="item.WareHouse_Line"
        is-link
        @click="setAndJump(item.Line, item.WareHouse_Line)"
      />
    </van-cell-group>
    <div class="areabottom">
      <van-button type="warning" block class="logout" @click="handleLogout"
        >退出</van-button
      >
    </div>
  </div>
</template>

<script>
import { Cell, CellGroup } from "vant";
import { mapGetters, mapActions } from "vuex";

export default {
  components: {
    [Cell.name]: Cell,
    [CellGroup.name]: CellGroup,
  },
  name: "SelectProductionLine",
  computed: {
    ...mapGetters(["productionLines", "user"]),
  },
  methods: {
    ...mapActions(["logout"]),
    handleLogout() {
      this.logout().then(() => {
        this.$router.push("/login");
      });
    },
    setAndJump(item1, item2) {
      this.$store.commit("SET_PRODUCTION_LINE", item1);
      this.$store.commit("SET_WAREHOUSE_LINE", item2);
      console.log(this.productionLines);
      console.log(this.$store.getters.WarehouseId);
      switch (this.$store.getters.productionLine) {
        case "MD5":
          this.$router.push("/mdhome");
          break;
        case "MD4":
          this.$router.push("/md4home");
          break;
        case "LiquidC":
          this.$router.push("/ldhome");
          break;
        case "CCO":
          this.$router.push("/ccohome");
          break;
        case "Con":
          this.$router.push("/conhome");
          break;
        case "Sugar":
          this.$router.push("/ccohome");
          break;
        case "WhiteC":
          this.$router.push("/ccohome");
          break;
        case "MM1Make":
          this.$router.push("/m1home");
          break;
        case "MM2Make":
          this.$router.push("/m2home");
          break;
        case "MM1Pack":
          this.$router.push("/m1m2packhome");
          break;
        case "MM2Pack":
          this.$router.push("/m1m2packhome");
          break;
        case "MMPS":
          this.$router.push("/mmpshome");
          break;
        case "MMPeanut":
          this.$router.push("/ccohome");
          break;
        case "MMBC":
          this.$router.push("/m1home");
          break;
        case "MM3Make":
          this.$router.push("/mm3home");
          break;
        case "KIND1":
          this.$router.push("/home");
          break;
        case "Snick1":
          this.$router.push("/home");
          break;
        case "Pan+PIPS":
          this.$router.push("/dovehome");
          break;
        case "PIPS":
          this.$router.push("/dovehome");
          break;
        case "BARLINE":
          this.$router.push("/m2home");
          break;
        case "PSP":
          this.$router.push("/m1home");
          break;
        case "DovePanPacking":
          this.$router.push("/dovemakehome");
          break;
        case "DovePanSpray":
          this.$router.push("/doveputhome");
          break;
        case "DovePanPolishing":
          this.$router.push("/dovelighthome");
          break;
        case "PSPPACK":
          this.$router.push("/m1home");
          break;
        default:
          this.$router.push("/home");
          break;
      }
    },
  },
};
</script>

<style scoped>
.logout {
  position: fixed;
  bottom: 0;
}
.areabottom {
  height: 2rem;
}
</style>
